package servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;
import pojo.User;
import utils.db.impl.UserFetcher;

/**
 * Servlet implementation class InformationUserServlet
 */
@WebServlet("/InformationUserServlet")
public class InformationUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		if (request.getParameter("userId") != null) {
			PrintWriter out = response.getWriter();
			int userId = Integer.parseInt(request.getParameter("userId"));
			UserFetcher d = new UserFetcher();
			User u = d.getUserById(userId);
			JSONObject jsonReturn = new JSONObject();
			jsonReturn.put("type", String.valueOf(u.getType()));
			out.print(jsonReturn);
			out.flush();
		}
	}

}
